package com.finace.money.ui.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.finace.money.R;
import com.finace.money.common.util.UIUtil;
import com.finace.money.data.bean.DealInfoBean;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by zhangpeng on 2017/12/4.
 */

public class DealInfoAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {

    private List<DealInfoBean> mData;

    public void setmData(List<DealInfoBean> mData) {
        this.mData = mData;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new DealInfoViewHolder(LayoutInflater.from(UIUtil.getContext()).
                inflate(R.layout.item_deal_info, parent, false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, int position) {

        if(holder instanceof DealInfoViewHolder){
            DealInfoViewHolder dealInfoViewHolder = (DealInfoViewHolder) holder;
            dealInfoViewHolder.tvInfoTitle.setText(mData.get(position).getTitle());
            dealInfoViewHolder.tvInfoContent.setText(mData.get(position).getContent());
        }
    }

    @Override
    public int getItemCount() {
        return (null != mData && mData.size()>0)? mData.size():0;
    }

    public class DealInfoViewHolder extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_info_title)
        TextView tvInfoTitle;
        @BindView(R.id.tv_info_content)
        TextView tvInfoContent;

        public DealInfoViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }
}
